package org.apache.flink.runtime.rest.handler.job.metrics;

import java.util.Map;

import javax.annotation.Nullable;

import org.apache.flink.api.common.time.Time;
import org.apache.flink.runtime.rest.handler.HandlerRequest;
import org.apache.flink.runtime.rest.legacy.metrics.MetricFetcher;
import org.apache.flink.runtime.rest.legacy.metrics.MetricStore;
import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
import org.apache.flink.runtime.rest.messages.job.metrics.JobManagerMetricsHeaders;
import org.apache.flink.runtime.rest.messages.job.metrics.ConsumerManagerMetricsMessageParameters;
import org.apache.flink.runtime.rpc.retriever.GatewayRetriever;
import org.apache.flink.runtime.webmonitor.RestfulGateway;

/** Handler that returns ConsumerManager metrics. */
public class ConsumerManagerMetricsHandler
        extends AbstractMetricsHandler<ConsumerManagerMetricsMessageParameters> {

    public ConsumerManagerMetricsHandler(
            final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
            final Time timeout,
            final Map<String, String> headers,
            final MetricFetcher metricFetcher) {
        super(
                leaderRetriever,
                timeout,
                headers,
                JobManagerMetricsHeaders.getInstance(),
                metricFetcher);
    }

    @Nullable
    @Override
    protected MetricStore.ComponentMetricStore getComponentMetricStore(
            final HandlerRequest<EmptyRequestBody> request, final MetricStore metricStore) {
        return metricStore.getConsumerManagerMetricStore();
    }
}
